package com.design.flyweight.game;

import java.util.HashMap;
import java.util.Map;

// 装备工厂类
class EquipmentFactory {
    private Map<String, Equipment> equipmentMap;

    public EquipmentFactory() {
        equipmentMap = new HashMap<>();
    }

    // 获取装备对象
    public Equipment getEquipment(String type, String name) {
        String key = type + "_" + name;

        if (!equipmentMap.containsKey(key)) {
            if ("Weapon".equalsIgnoreCase(type)) {
                equipmentMap.put(key, new Weapon(name));
            } else if ("Armor".equalsIgnoreCase(type)) {
                equipmentMap.put(key, new Armor(name));
            } else {
                throw new IllegalArgumentException("Invalid equipment type: " + type);
            }
        }

        return equipmentMap.get(key);
    }
}
